package com.ruoyi.reservationserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.reservationserver.dao.CourtTypeDao;
import com.ruoyi.reservationserver.entity.CourtType;
import com.ruoyi.reservationserver.service.CourtTypeService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 场地表(CourtType)表服务实现类
 *
 * @author makejava
 * @since 2023-07-04 16:21:46
 */
@Service("courtTypeService")
public class CourtTypeServiceImpl extends ServiceImpl<CourtTypeDao,CourtType> implements CourtTypeService {
    @Resource
    private CourtTypeDao courtTypeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param courtTypeId 主键
     * @return 实例对象
     */
    @Override
    public CourtType queryById(Integer courtTypeId) {
        return this.courtTypeDao.queryById(courtTypeId);
    }

    /**
     * 分页查询
     *
     * @param courtType 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CourtType> queryByPage(CourtType courtType, PageRequest pageRequest) {
        long total = this.courtTypeDao.count(courtType);
        return new PageImpl<>(this.courtTypeDao.queryAllByLimit(courtType, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param courtType 实例对象
     * @return 实例对象
     */
    @Override
    public CourtType insert(CourtType courtType) {
        this.courtTypeDao.insert(courtType);
        return courtType;
    }

    /**
     * 修改数据
     *
     * @param courtType 实例对象
     * @return 实例对象
     */
    @Override
    public CourtType update(CourtType courtType) {
        this.courtTypeDao.update(courtType);
        return this.queryById(courtType.getCourtTypeId());
    }

    /**
     * 通过主键删除数据
     *
     * @param courtTypeId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer courtTypeId) {
        return this.courtTypeDao.deleteById(courtTypeId) > 0;
    }
}
